package com.example.seakdreamandroid.sleep;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.seakdreamandroid.BeforeSleepActivity;
import com.example.seakdreamandroid.LoginActivity;
import com.example.seakdreamandroid.R;

import java.util.Date;
/*睡觉*/

/**
 * 张清雅
 */
public class Sleep extends Fragment {

    private TextView tvTime;
    private TextView tvGreetings;
    private RelativeLayout relBg;
    private ImageButton imgBtnNap,imgBtnAlarmClock,imgBtnBeforeSleep;

    private LinearLayout logSleep;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        relBg = (RelativeLayout) inflater.inflate(R.layout.activity_sleep,container, false);
        getViews();
        //设置背景和问候语
        getData(tvTime,tvGreetings,relBg);
        //设置点击事件
        setListener();
        return relBg;
    }

    private void setListener() {
        imgBtnNap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(),NapActivity.class);
                startActivity(intent);
            }
        });
        imgBtnAlarmClock.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(),AlarmClockAndPrompt.class);
                Bundle bundle =new Bundle();
                bundle.putInt("flag1",1);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
        imgBtnBeforeSleep.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), BeforeSleepActivity.class);
                startActivity(intent);
            }
        });
        logSleep.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), RecordSleep.class);
                startActivity(intent);
            }
        });
    }

    private void getData(TextView tvTime, TextView tvGreetings, RelativeLayout relBg) {
        Date myDate = new Date();
        int hours = myDate.getHours();
        if (hours < 11) {
            tvTime.setText("上午好");
            tvGreetings.setText("白天晒晒太阳，有助于分泌褪黑素哦");
            relBg.setBackgroundResource(R.mipmap.morning);
        } else if (hours < 13) {
            tvTime.setText("中午好");
            tvGreetings.setText("日间小憩一下，可以缓解身体和大脑疲劳");
            relBg.setBackgroundResource(R.mipmap.morning);
        } else if (hours < 18) {
            tvTime.setText("下午好");
            tvGreetings.setText("下午茶可以帮助我们保持精力，放松身心");
            relBg.setBackgroundResource(R.mipmap.morning);
        } else if (hours < 24) {
            tvTime.setText("晚上好");
            tvGreetings.setText("听听深睡脑波，可以减少睡前大脑兴奋");
            relBg.setBackgroundResource(R.mipmap.morning);
        }
    }

    private void getViews() {
        tvTime = relBg.findViewById(R.id.tv_time);
        tvGreetings = relBg.findViewById(R.id.tv_greetings);
        imgBtnNap = relBg.findViewById(R.id.imgBtn_nap);
        imgBtnAlarmClock = relBg.findViewById(R.id.imgBtn_alarmClock);
        imgBtnBeforeSleep = relBg.findViewById(R.id.imgBtn_beforeSleep);
        logSleep = relBg.findViewById(R.id.lin_LogSleep);
    }

}